home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FileHelpers.c
-
- Contains: Functions to help you when working with files.
-
- Written by: Andy Bachorski
-
- Copyright: Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/21/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
- // Conditionals to setup the build environment the way we like it.
- #include "PrivateConditionals.h"
-
-
- //********** Universal Headers ****************************************
-
- #include <Errors.h>
- #include <Files.h>
- #include <Resources.h>
-
-
- //********** Project Headers ****************************************
-
- #include "FileHelpers.h"
-
-
- //******************************************************************************
-
- OSErr OpenResFileForWrite( const FSSpec *fileFSSPtr, SInt16 *resFileRef )
- {
- OSErr anErr = noErr;
-
- *resFileRef = FSpOpenResFile( fileFSSPtr, fsRdWrPerm );
- if ( *resFileRef == -1 )
- {
- anErr = ResError();
- }
- else // Got it open, but can it be written to?
- {
- if ( ! IsResourceFileRefNumWritable( *resFileRef ) )
- {
- anErr = permErr;
- CloseResFile( *resFileRef );
- *resFileRef = -1;
- }
- }
-
- return anErr;
- }//end OpenResFileForWrite
-
- //**************************************************************************
-
- Boolean IsResourceFileRefNumWritable( SInt16 refNum )
- {
- FCBPBRec fcbPB;
- Boolean result = false;
-
- fcbPB.ioNamePtr = nil;
- fcbPB.ioVRefNum = 0;
- fcbPB.ioRefNum = refNum;
- fcbPB.ioFCBIndx = 0;
- if ( PBGetFCBInfoSync( &fcbPB ) == noErr )
- {
- result = ( (fcbPB.ioFCBFlags & (1 << 8)) != 0 );
- }
-
- return result;
- }//end IsResourceFileRefNumWritable
-
- //******************************************************************************
-